def Input():
    firstLine, secondLine = input(), input()
    return firstLine, secondLine
    
def Separate(firstLine, secondLine):
    peopleAndTaps = firstLine.split(' ')
    eachTime = secondLine.split(' ')
    eachTime_sort = eachTime[:]
    eachTime.sort()

    return peopleAndTaps, eachTime, eachTime_sort
    
def StrToInt(peopleAndTaps, eachTime_sort):
    for i in range(0, len(eachTime_sort)):
        eachTime_sort[i] = int(eachTime_sort[i])
    for i in range(0, len(peopleAndTaps)):
        peopleAndTaps[i] = int(peopleAndTaps[i])

def GetNAndR(peopleAndTaps):
    n, r = peopleAndTaps[0], peopleAndTaps[1]
    return n, r

def CalCu(eachTime_sort, r):
    time = 0
    while len(eachTime_sort) > 0:
        for i in range(1, min(r, len(eachTime_sort))):
            eachTime_sort[i] -= eachTime_sort[0]
        time += eachTime_sort[0] * len(eachTime_sort)
        del(eachTime_sort[0])
    return time
        
def main():
    firstLine, secondLine = Input()
    peopleAndTaps, eachTime, eachTime_sort = Separate(firstLine, secondLine)
    StrToInt(peopleAndTaps, eachTime_sort)
    n, r = GetNAndR(peopleAndTaps)
    print(CalCu(eachTime_sort, r))

if __name__ == '__main__':
	main()
